const express = require("express");
const feedbackRouter=express.Router();
const feedbackSer=require('../../services/feedbackService');

//添加反馈
feedbackRouter.post('/add',async (req,res)=>{
    let {title,content,Initiator}=req.body;
    if(title==undefined||content==undefined || Initiator==undefined) return res.send({
        data:{},meta:{msg:"传递参数为空",status: 400}
    })
    let result = await feedbackSer.addFeedback({title,content,Initiator});
    res.send({
        data:{
            result
        },
        meta:{
            msg:"反馈成功",
            status: 201
        }
    })
})

// 添加反馈结果
feedbackRouter.put('/addover',async (req,res)=>{
    let {id,handleResult}=req.body;
    if(id==undefined||handleResult==undefined) return res.send({
        data:{},
        meta:{msg: '未添加参数',status: 400}
    })
    let result = await feedbackSer.overFeedback(id,{handleResult});
    if(result==false) return res.send({
        data:{},meta:{msg:'添加失败',status: 422}
    })
    res.send({
        data:{},
        meta:{
            msg: '添加成功',status: 200
        }
    })
})

//获取反馈列表
feedbackRouter.get('/lists',async (req,res)=>{
    let {pagenum,pagesize}=req.query;
    let result = await feedbackSer.findFeedback(pagenum,pagesize);
    res.send({data:{...result},meta:{msg:'获取成功',status:200}})
})

//获取详细反馈信息
feedbackRouter.get('/getOver',async (req,res)=>{
    let {id}=req.query;
    if(id==undefined) return res.send({data:{},meta:{msg:"参数为空",status: 400}})
    let [result] = await feedbackSer.findOver(id);
    res.send({data:{result},meta:{msg:"获取成功",status: 200}})
})


module.exports=feedbackRouter